﻿using iTelluro.Explorer.Infrastructure.CrossCutting.Logging;
using iTelluro.Explorer.Infrastructure.CrossCutting.NetFramework.Logging;
using Quartz;
using SXMeteorological.Data.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SXMeteorological.DataSyn.SoilHumidity
{
    public class SoilHumidityJob:IJob
    {
        private readonly ILogger _logger;
        public SoilHumidityJob()
        {
            _logger = LoggerFrameFactory.CreateLog();
            _logger.LogInfo("执行土壤相对湿度任务构造函数");
        }


        public void Execute(IJobExecutionContext context)
        {
            for (int i = 1; i < 11;i++ )
            {
                SoilHumidity(i.ToString());
                ContainWaterRate(i.ToString());
                ContainWeightWater(i.ToString());
                StorgeWater(i.ToString());
            }
        }
        /// <summary>
        /// 土壤相对湿度SRHU   z这个是对的
        /// </summary>
        /// <param name="cm"></param>
        private void SoilHumidity(string cm)
        {
            try
            {
                string interfaceName = "getAgmeEleInRegionByTimeAndDepth";
                string returnValue = "Lat,Lon,SRHU";
                string featureName = cm+"0cm土壤相对湿度";
                string time = DateTime.UtcNow.ToString("yyyyMMddHH") + "0000";
                string dataCode = "AGME_CHN_SOIL_HOR";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\humidity.txt";
                string mapName = cm+"0cm土壤相对湿度图";
               // _logger.LogInfo(featureName+"**"+mapName+"***"+returnValue);
                string soilDepths=cm+"0";
                CreateMap.CreateSoilFeatureMap(interfaceName, returnValue, dataCode, featureName, mapName, time, colorpath, "h", soilDepths);
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省{0}0cm土壤湿度数据生成失败#{1}：{2}",cm, DateTime.Now, ex.Message));
            }
        }
        /// <summary>
        /// 土壤体积含水量(克/立方厘米)	SVWC  对的
        /// </summary>
        private void ContainWaterRate(string cm)
        {
            try
            {
                string interfaceName = "getAgmeEleInRegionByTimeAndDepth";
                string returnValue = "Lat,Lon,SVWC";
                string featureName = cm + "0cm土壤体积含水率";
                string time = DateTime.UtcNow.ToString("yyyyMMddHH") + "0000";
                string dataCode = "AGME_CHN_SOIL_HOR";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\humidity.txt";
                string mapName = cm + "0cm土壤体积含水率图";
                // _logger.LogInfo(featureName+"**"+mapName+"***"+returnValue);

                string soilDepths = cm + "0";
                CreateMap.CreateSoilFeatureMap(interfaceName, returnValue, dataCode, featureName, mapName, time, colorpath, "h", soilDepths);
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省{0}0cm土壤体积含水率生成失败#{1}：{2}", cm, DateTime.Now, ex.Message));
            }
        }
        /// <summary>
        /// 土壤重量含水率SWWC   错的
        /// </summary>
        private void ContainWeightWater(string cm)
        {
            try
            {
                string interfaceName = "getAgmeEleInRegionByTimeAndDepth";
                string returnValue = "Lat,Lon,SWWC";
                string featureName = cm + "0cm土壤重量含水率";
                string time = DateTime.UtcNow.ToString("yyyyMMddHH") + "0000";
                string dataCode = "AGME_CHN_SOIL_HOR";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\humidity.txt";
                string mapName = cm + "0cm土壤重量含水率图";
                // _logger.LogInfo(featureName+"**"+mapName+"***"+returnValue);
                string soilDepths = cm + "0";
                CreateMap.CreateSoilFeatureMap(interfaceName, returnValue, dataCode, featureName, mapName, time, colorpath, "h", soilDepths);
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省{0}0cm土壤湿度数据生成失败#{1}：{2}", cm, DateTime.Now, ex.Message));
            }
        }
        /// <summary>
        /// 土壤有效水分贮存量SVMS
        /// </summary>
        private void StorgeWater(string cm)
        {
            try
            {
                string interfaceName = "getAgmeEleInRegionByTimeAndDepth";
                string returnValue = "Lat,Lon,SVMS" ;
                string featureName = cm + "0cm土壤有效水分贮存量";
                string time = DateTime.UtcNow.ToString("yyyyMMddHH") + "0000";
                string dataCode = "AGME_CHN_SOIL_HOR";
                string colorpath = AppDomain.CurrentDomain.BaseDirectory + @"color\humidity.txt";
                string mapName = cm + "0cm土壤有效水分贮存量图";
                // _logger.LogInfo(featureName+"**"+mapName+"***"+returnValue);

                string soilDepths = cm + "0";
                CreateMap.CreateSoilFeatureMap(interfaceName, returnValue, dataCode, featureName, mapName, time, colorpath, "h", soilDepths);
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("陕西省{0}0cm土壤湿度数据生成失败#{1}：{2}", cm, DateTime.Now, ex.Message));
            }
        }

    }
}
